package com.EquationSolver;

class SquareEquation
{
	private double a,b,c;
	
	private double root1, root2, min, det;
	
	SquareEquation(double a,double b, double c)
	{
		this.a = a;
		this.b = b;
		this.c = c;
	}
	
	void Solve()
	{
		det = b * b - 4 * a *c;
		if (a==0)
		{
			root1 = root2 = -c / b;
		}else if (det == 0)
		{
			root1 = root2 = -b / 2 / a;
		}else if (det > 0)
		{
			root1 = (-b + Math.sqrt(det))/2/a;
			root2 = (-b - Math.sqrt(det))/2/a;
		}
	}
	
	int rootsNumber()
	{
		if(det>0)
		{
			return 2;
		}else if (det == 0)
		{
			return 1;
		}else
		{
			return 0;
		}
	}
	
	double valueAt(double x)
	{
		return a * x * x + b * x + c;
	}
	
	double root1(){return root1;}
	double root2(){return root2;}
	double min(){return min;}
	double det(){return det;}
	
	String description()
	{
		return String.format("%.1f * x^2 + %.1f * x + %.1f", a, b, c);
	}
};
